<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// Init all settings 2 main module : client and admin
function init_settings()
{
    global $CI;
    
    $module     = $CI->router->fetch_module();
    $controller = $CI->router->class;
    $method     = $CI->router->method;

	if($module == 'client') {
        if($controller == 'user') return;
        if(!isset($_SESSION['_user'])) {
            redirect(base_url().'login/');die;
        }
        elseif($controller != 'home') {
            $CI->load->model('admin/auth_model');
            $allow = $CI->auth_model->check_permission($controller, $method);
            
            if(!$allow) {
                echo "<script>alert('err!');location.href='".base_url()."';</script>";exit;
            }
        }
    }
    
    if($module == 'admin') {
        if($controller == 'auth') return;
        
        if(!isset($_SESSION['_user'])) {
            admin_redirect('login'); exit;
        }
        $CI->load->model('admin/auth_model');
        if(!$CI->auth_model->check_login_admin())redirect(base_url().'login/');
    }
    
	
}
